<?php //Controller strony głównej

include_once "BaseModel.php";

class LoginModel extends BaseModel {
	
	public function getData($params) {
		if($params->action == 'logout') {
			$data->headerEntries[] = '<meta HTTP-EQUIV="REFRESH" content="2; url='.URI::getUrl(null).'">';
			Session::logOffUser();
			return $data;
		}
		if(isset($params->postParams->login))
			$user = UserDAO::getInstance()->getUser($params->postParams->login);
		else
			$user = null;
		if(!$user) {
			$data->logged = false;
			return $data;
		}
		//echo $user;
		//echo Hasher::hash($params->postParams->password).'<br>';
		//echo $user->getPassHash();
		if($user->getPassHash() == Hasher::hash($params->postParams->password)) {
			$data->logged = $user->getLogin();
			$data->headerEntries[] = '<meta HTTP-EQUIV="REFRESH" content="2; url='.URI::getUrl(null, $user->getLogin()).'">';
			Session::setLoggedUserName($user->getLogin());
		} else {
			$data->logged = false;
		}
		return $data;
	}
}

?>